#include"Comm.hpp"
#include"Log.hpp"

const int flags=IPC_CREAT|IPC_EXCL;
int main()
{
    key_t key=CreatKey();
    Log() << "key: " << key << "\n";
    Log() << "create share memory begin\n";
    int shmid=shmget(key,MEM_SIZE,flags);
    if(shmid<0)
    {
        Log()<<"shmget: "<<strerror(errno)<<endl;
        return 2;
    }
    Log() << "create shm success, shmid: " << shmid << "\n";
    sleep(5);

    char* str=(char*)shmat(shmid,nullptr,0);
    Log() << "attach shm : " << shmid << " success\n";
 
    sleep(5);
    // 用它
    // 2. 去关联
    shmdt(str);
    Log() << "detach shm : " << shmid << " success\n";
    sleep(5);

    shmctl(shmid,IPC_RMID,nullptr);
    Log() << "delete shm : " << shmid << " success\n";
 
    sleep(5);
    return 0;
}